import collections
class Solution(object):
    def numIdenticalPairs(self, nums):
        c = collections.Counter(nums)
        ans = 0
        for key in c:
            ans += c[key] * (c[key] - 1) // 2
        return ans